System and method for SIMD code generation in the presence of optimized misaligned data reorganization

ABSTRACT

A method, computer program product, and information handling system for generating loop code to execute on Single-Instruction Multiple-Datapath (SIMD) architectures, where the loop operates on datatypes having different lengths, is disclosed. Further, a preferred embodiment of the present invention includes a novel technique to efficiently realign or shift arbitrary streams to an arbitrary offset, regardless whether the alignments or offsets are known at the compile time or not. This technique enables the application of advanced alignment optimizations to runtime alignment. This allows sequential loop code operating on datatypes of disparate length to be transformed (“simdized”) into optimized SIMD code through a fully automated process.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation-in-part of commonly assigned,co-pending U.S. Non-Provisional patent application Ser. No. 10/862,483,entitled “SYSTEM AND METHOD FOR EFFICIENT DATA REORGANIZATION TO SATISFYDATA ALIGNMENT CONSTRAINTS,” filing date Jun. 7, 2004, Attorney DocketNo. AUS920040386US1, which is incorporated herein by reference. Thisapplication is also related to U.S. Non-Provisional patent applicationSer. No. 10/______, entitled “SYSTEM AND METHOD FOR SIMD CODE GENERATIONFOR LOOPS WITH MIXED DATA LENGTHS,” Attorney Docket No. AUS920040385US1;U.S. Non-Provisional patent application Ser. No. 10______, entitled“FRAMEWORK FOR GENERATING MIXED-MODE OPERATIONS IN LOOP-LEVELSIMDIZATION,” Attorney Docket No. AUS920040388US1; U.S. Non-Provisionalpatent application Ser. No. 10/______, entitled “FRAMEWORK FORINTEGRATED INTRA- AND INTER-LOOP AGGREGATION OF CONTIGUOUS MEMORYACCESSES FOR SIMD VECTORIZATION,” Attorney Docket No. AUS920040389US1;and U.S. Non-Provisional patent application Ser. No. 10/______, entitled“FRAMEWORK FOR EFFICIENT CODE GENERATION USING LOOP PEELING FOR SIMDLOOP CODE WITH MULTIPLE MISALIGNED STATEMENTS,” Attorney Docket No.AUS920040390US1, which are all filed even date hereof, assigned to thesame assignee, and incorporated herein by reference.

BACKGROUND OF THE INVENTION

1. Technical Field

The present invention relates in general to a system and method forvectorizing loop code for execution on Single Instruction MultipleDatapath (SIMD) architectures that impose strict alignment constraintson the data.

2. Description of the Related Art

Multimedia extensions (MMEs) have become one of the most popularadditions to general-purpose microprocessors. Existing multimediaextensions can be characterized as Single Instruction Multiple Datapath(SIMD) units that support packed fixed-length vectors. The traditionalprogramming model for multimedia extensions has been explicit vectorprogramming using either (in-line) assembly or intrinsic functionsembedded in a high-level programming language. Explicit vectorprogramming is time-consuming and error-prone. A promising alternativeis to exploit vectorization technology to automatically generate SIMDcodes from programs written in standard high-level languages.

Although vectorization has been studied extensively for traditionalvector processors decades ago, vectorization for SIMD architectures hasraised new issues due to several fundamental differences between the twoarchitectures. See, e.g., Ren, Gang, et al. A Preliminary Study on theVectorization of Multimedia Applications. In 16th International Workshopof Languages and Compilers for Parallel Computing. October 2003. Todistinguish between the two types of vectorization, we refer to thelatter as simdization. One such fundamental difference comes from thememory unit. The memory unit of a typical SIMD processor bears moreresemblance to that of a wide scalar processor than to that of atraditional vector processor. In the VMX instruction set found oncertain POWERPC microprocessors (produced by International BusinessMachines Corporation and Motorola, Inc.), for example, a loadinstruction loads 16-byte contiguous memory from 16-byte aligned memory,ignoring the last 4 bits of the memory address in the instruction. Thesame applies to store instructions. In this paper, architectures withalignment constraints refer to machines that support only loads andstores of register-length aligned memory.

There has been a recent spike of interest in compiler techniques toautomatically extract SIMD parallelism from programs. See, e.g., LARSEN,Samuel, et al. Exploiting Superword Level Parallelism with MultimediaInstruction Sets. In Proceedings of SIGPLAN Conference on ProgrammingLanguage Design and Implementation. June 2000, pp. 145-156; BIK, Aart,et al. Automatic Intra-Register Vectorization for the IntelArchitecture. Int. J. of Parallel Programming. April 2002, vol. 30, no.2, pp. 65-98; KRALL, Andreas, et al. Compilation Techniques forMultimedia Processors. Int. J. of Parallel Programming. August 2000,vol. 28, no. 4, pp. 347-361; SRERMAN, N., et al. A Vectorizing Compilerfor Multimedia Extensions. Int. J. of Parallel Programming, August 2000,vol. 28, no. 4, pp. 363-400; LEE, Corinna G., et al. Simple VectorMicroprocessors for Multimedia Applications. In Proceedings ofInternational Symposium on Microarchitecture. 1998, pp. 25-36; andNAISHLOS, Dorit, et al. Vectorizing for a SIMD DSP Architecture. InProceedings of International Conference on Compilers, Artchitectures,and Synthesis for Embedded Systems. October 2003, pp. 2-11. This upsurgewas driven by the increasing prevalence of SIMD architectures inmultimedia processors. Two principal techniques have been used, thetraditional loop-based vectorization pioneered for vector supercomputers(e.g., ALLEN, John Randal, et al. Automatic Translation of FortranPrograms to Vector Form. ACM Transactions on Programming Languages andSystems. October 1987, vol. 4, pp. 491-542; and ZIMA, Hans, et al.Supercompilers for Parallel and Vector Computers. Reading, MA:Addison-Wesley/ACM Press, 1990. ISBN 0201175606.) and theunroll-and-pack approach first proposed by Larsen and Amarasinghe inLARSEN, Samuel, et al. Exploiting Superword Level Parallelism withMultimedia Instruction Sets. In Proceedings of SIGPLAN Conference onProgramming Language Design and Implementation. June 2000, pp. 145-156.

The alignment constraints of SIMD memory units present a great challengeto automatic simdization. Consider the code fragment in FIG. 1 whereinteger arrays a, b, and c are aligned (An aligned reference means thatthe desired data reside at an address that is a multiple of the vectorregister size.). Although this loop is easily vectorizable fortraditional vector processors, it is non-trivial to simdize it for SIMDarchitectures with alignment constraints. Hence, the most commonly usedpolicy today is to simdize a loop only if all memory references in theloop are aligned.

A very extensive discussion of alignment considerations is provided byLARSON, Samuel, et al. Increasing and Detecting Memory AddressCongruence. In Proceedings of 11th International Conference on ParallelArchitectures and Compilation Techniques. September 2002. However,LARSON is concerned with the detection of memory alignments and withtechniques to increase the number of aligned references in a loop,whereas our work focuses on generating optimized SIMD codes in thepresence of misaligned references. The two approaches are complementary.The use of loop peeling to align accesses was discussed in LARSON aswell as in the aforementioned BIK reference. The loop peeling scheme isequivalent to the eager-shift policy with the restriction that allmemory references in the loop must have the same misalignment. Evenunder this condition, our scheme has the advantage of generatingsimdized prologue and epilogue, which is the by-product of peeling fromthe simdized loop.

Direct code generation for misaligned references have been discussed byseveral prior works. The vectorization of misaligned loads and storesusing the VIS instruction set is described in CHEONG, Gerald, et al. AnOptimizer for Multimedia Instruction Sets. In Second SUIF CompilerWorkshop. August 1997. The aforementioned BIK, et al. referencedescribed a specific code sequence of aligned loads and shuffle to loadmemory references that cross cache line boundaries, which is implementedin Intel's compiler for SSE2. However, their method is not discussed inthe context of general misalignment handling.

The VAST compiler, a commercial product by Crescent Bay Software, hassome limited ability to simdize loops with multiple misalignedreferences, unknown loop bounds, and runtime alignments, and exploit thereuse when aligning a steam of contiguous memory. The VAST compiler,however, produces less than optimal simdized code, as its highlygeneralized scheme for handling mis-alignment can produce additionalcompilation overhead.

An interesting simdization scheme using indirect register accesses isdiscussed in the aforementioned NAISHLOS, et al. reference. However,their method is specific to the eLite processor, which supports moreadvanced vector operations (such as gather and scatter operations) thanare available on typical MME processors. In SHIN, Jaewook, et al.Compiler-Controlled Caching in Superword Register Files for MultimediaExtension Architectures. In Proceedings of International Conference onParallel Architectures and Compilation Techniques. September 2002,register packing and shifting instructions were used to exploit temporaland spatial reuse in vector registers. However, their work does notaddress alignment handling.

Another work that is of note, but which is in the area of compiling fordistributed memory systems as opposed to SIMD architectures, isCRATTERJEE, Siddhartha, et al. Modeling Data-Parallel Programs with theAlignment-Distribution Graph. J. of Programming Languages. 1994, vol. 2,no. 3, pp. 227-258.

In the incorporated U.S. patent application Ser. No. 10/______,(hereinafter EICHENBERGER) a generic alignment handling framework thatsimdizes loops with arbitrary misalignments is disclosed. According tothis framework, contiguous data accessed in a loop is viewed as streams,and aligning data to satisfy alignment constraints is modeled asshifting streams. Consider, for example, the (C-language) loop in FIG. 1where the base of arrays a, b, and C are aligned (An aligned referencemeans that the desired data reside at an address that is a multiple ofthe vector register size). The grey boxes in FIG. 2A highlight the threememory streams represented by references a[i+2], b[i+1], and c[i+3] overthe lifetime of the loop. Focusing on the first value of each stream,i.e., data accessed by the i=0 loop iteration, one can see from FIG. 2Athat the a[2], b[1], and c[3] values are all misaligned with respect toeach others. A valid simdization requires streams involved in acomputation to have matching alignments. This condition can be satisfiedby realigning misaligned streams using stream shift operations. FIG. 2Bshows a minimum cost simdization of the loop in FIG. 1 that involves twoshifts that respectively shifts the b[i+1] and c[i+3] memory streams tothe alignment of the a[i+2] memory stream. The three streams have thenthe same alignment, satisfying the alignment constraints of the vadd andvstore operations.

Although runtime alignment is handled in the framework of EICHENBERGER,it is not as efficient as the handling of compile time alignment. Due tocode generation issues, stream shifts must be implemented as eitherstream shift left or stream shift right. In the presence of runtimealignment, the relative alignment of 2 streams is clearly unknown atcompile time. In such cases, the approach taken in EICHENBERGER is toshift left each input memory stream to the leftmost position (registeroffset 0), perform the computation, and shift right the result to thestore memory alignment. For example, in the loop in FIG. 1, this runtimeshift policy is equivalent to the simdization shown in FIG. 2C where 3shifts are required instead of 2, increasing the alignment overhead by50%.

In addition, existing technologies fail to adequately address the issueof data-length conversion in the generation of vectorized code for SIMDprocessors, where the source or destination data streams are misalignedwith respect to each other. For example, one may write a loop that addsa vector of 16-bit “short” integers to a vector of 32-bit “long”integers to obtain a result that is a vector of 32-bit integer values(e.g., the case where b is an array of short integers and a and C arearrays of long integers in the loop of FIG. 1).

Thus, what is needed is a method for automatically simdizing sequentialprogram code into parallelized SIMD code in the presence of vectormisalignments that are undefined at compile-time and where a conversionbetween datatypes of different lengths is needed. The present inventionprovides a solution to these and other problems, and offers otheradvantages over previous solutions.

SUMMARY

A preferred embodiment of the present invention provides a method,computer program product, and information handling system for generatingloop code to execute on Single-Instruction Multiple-Datapath (SIMD)architectures, where the loop operates on datatypes having differentlengths. A preferred embodiment of the present invention a noveltechnique to efficiently realign or shift arbitrary streams to anarbitrary offset, regardless whether the alignments or offsets are knownat the compile time or not. This technique enables the application ofadvanced alignment optimizations to runtime alignment. Length conversionoperations, for packing and unpacking data values, are included in thealignment handling framework. These operations are formally defined interms of standard SIMD instructions that are readily available onvarious SIMD platforms. This allows sequential loop code operating ondatatypes of disparate length to be transformed (“simdized”) intooptimized SIMD code through a fully automated process.

The foregoing is a summary and thus contains, by necessity,simplifications, generalizations, and omissions of detail; consequently,those skilled in the art will appreciate that the summary isillustrative only and is not intended to be in any way limiting. Otheraspects, inventive features, and advantages of the present invention, asdefined solely by the claims, will become apparent in the non-limitingdetailed description set forth below.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention may be better understood, and its numerousobjects, features, and advantages made apparent to those skilled in theart by referencing the accompanying drawings.

FIG. 1 is a diagram of a loop in a C-like programming language that maybe simdized/vectorized in accordance with a preferred embodiment of thepresent invention;

FIG. 2A is a diagram depicting a memory-misaligned set of data streamsinvolved in a loop;

FIG. 2B is a data reorganization graph representing a set of operationsperformed in simdized loop code generated according to the teachings ofthe incorporated EICHENBERGER reference using an eager-shift realignmentpolicy;

FIG. 2C is a data reorganization graph representing a set of operationsperformed in simdized loop code generated according to the teachings ofthe incorporated EICHENBERGER reference using an zero-shift realignmentpolicy;

FIG. 3A is a diagram depicting a stream shift operation according to themanner described in the incorporated EICHENBERGER reference, wherein thestream shift operation shifts a data stream to the right;

FIG. 3B is a diagram depicting a stream shift operation according to themanner described in the incorporated EICHENBERGER reference, wherein thestream shift operation shifts a data stream to the left;

FIG. 3C is a diagram depicting a stream shift operation corresponding tothe shift depicted in FIG. 3A, but in accordance with a preferredembodiment of the present invention, in which prepended values areutilized to ensure that the resulting generated code performs a leftshift operation;

FIG. 3D is a diagram depicting a stream shift operation corresponding tothe shift depicted in FIG. 3B, but in accordance with a preferredembodiment of the present invention, in which prepended values areutilized to ensure that the resulting generated code performs a leftshift operation;

FIG. 4 is a diagram depicting an algorithm in which a datareorganization graph is recursively traversed and all stream shiftoperations are normalized such that the resulting generated codeperforms only left shift operations;

FIG. 5 is a diagram depicting a simdized loop in accordance with apreferred embodiment of the present invention, in which a typeconversion between data types of different lengths is performed;

FIG. 6 is a flowchart representation of a process ofvectorizing/simdizing a loop in accordance with a preferred embodimentof the present invention; and

FIG. 7 is a block diagram of a computing device capable of implementingthe present invention.

DETAILED DESCRIPTION

1. Preliminary Matters

In this section, an overview of the alignment handling framework of theincorporated EICHENBERGER application is provided, some of the keyconcepts that a preferred embodiment of the present invention is builtupon are highlighted.

1.1. Alignment Constraints of a Valid Simdization

A valid vectorization for traditional vector units is only constrainedby dependencies. This is no longer sufficient when simdizing forarchitectures with alignment constraints. Consider the loopa[i+2]=b[i+1]+c[i+3] in FIG. 1. Since there is no loop-carrieddependence, a straightforward vectorization simply involves replacingscalar operations by corresponding vector operations. The generatedcode, however, will execute incorrectly if the hardware has alignmentconstraints. For example, in the VMX instruction set, due to the addresstruncation effect, a vector load from address of b[1] (i.e., vload b[1])actually loads b[0] . . . b[3], instead of the desired b[1] . . . b[4].Similarly, vload c[3] loads c[0] . . . C[3], instead of the desired c[3]. . . c[6]. Adding the two vectors yields b[0]+c[0] . . . b[3]+c[3],which is clearly not the result specified by the original b[i+1]+c[i+3]computation. Therefore, for hardware platforms with strict alignmentrequirements, a valid simdization must satisfy additional alignmentconstraints:

When simdizing a store operation, the byte offset of the data to bestored in the vector register must match the memory alignment of theoriginal store address.

When simdizing a binary operation, data involved in the originalcomputation must reside at the same byte offset in their respectivevector registers.

1.2 Stream and Stream Offset

The byte offset of data in a vector register is the key to expressingalignment constraints of a valid simdization. To capture the byte offsetproperty within a loop, the abstraction of stream is introduced. Thereare two types of streams, a memory stream that represents the sequenceof contiguous memory locations accessed by a memory reference over thelifetime of a loop, and a register stream that represents the sequenceof consecutive registers produced by a SIMD operation over the lifetimeof a loop.

Vector operations in a loop can be viewed as operations over streams. Avector load consumes a memory stream and produces a register stream. Asdata is read from memory in discrete chunks of 16 bytes, extra valuesmay be introduced at the beginning and the end of a register stream. Toindicate the boundaries of a register stream, the concept of a streamoffset is introduced. The stream offset is defined as the byte offset ofthe first desired value in the first register of a register stream. Notethat the stream offset of a register stream generated by of a vectorload is dictated by the alignment of the input memory stream. Thealignment of a memory stream is the alignment of the first element ofthe memory stream, namely the byte memory address of the first elementmodulo the byte width of the SIMD unit. For example, in FIG. 2B, thestream offset of vload b[i+1] (vload operation 210) is 4. Conversely, avector store consumes a register stream and produces a memory streamwhere the offset of the input register stream must match the alignmentof the memory stream. Finally, all other vector operations consumeregister streams with matching offsets and produce a register streamwith the same offset.

1.3 Stream Shift and Alignment Policies

A valid simdization requires the offsets of register streams involved inthe computation to satisfy alignment constraints. In the presence ofmisalignments, this property is only achievable by judiciously insertingdata reorganization operations to enforce the desired stream offset. Thestream shift operation, vshiftstream(S,c), is introduced for thispurpose. vshiftstream(S,c) shifts all values of a register stream Sacross consecutive registers of the stream to an offset of c. Note that,once the first element of a stream satisfies the alignment constraints,the rest of the stream also satisfies the alignment constraints. Thereare several policies to generate a valid simdization, each of which isdiscussed in greater detail in the incorporated EICHENBERGERapplication.

Zero-Shift Policy This policy shifts each misaligned load stream to 0,and shifts the register stream to be stored to the alignment of thestore address. The simdization in FIG. 2C uses the zero-shift policy. Itis the least optimized as it inserts a stream shift for each misalignedmemory stream. Left shift operation 218 shifts the “b” stream left byone value (4 bytes) to offset 0, and left shift operation 220 shifts the“C” stream left by three values (12 bytes) to offset 0. After additionoperation 221, the result is shifted right two values (8 bytes) by rightshift operation 222 from offset 0 to offset 8, for storage (storeoperation 223).

Eager-Shift Policy This policy shifts each load directly to thealignment of the store. The simdization in FIG. 2B uses this policy. Ina preferred embodiment, eager-shift is the default policy for compiletime alignment. Right shift operation 206 shifts the “b” stream right 4bytes to place the “b” stream in at the proper alignment for storing theresult (in “a”). Likewise, left shift operation 208 shifts the “C”stream left 4 bytes to place the “C” stream in at the proper alignmentfor storing the result (in “a”). The result of addition operation 214can then be directly stored into memory for array “a” (store operation216).

Lazy-Shift Policy This policy is based on the eager-shift policy butpushes the shift as close to the root of the expression tree aspossible. Consider the example of a[i+3]=b[i+1]+c[i+1]. This policyexploits the fact that b[i+1] and c[i+1] are relatively aligned, andthus can be safely operated on as is. Therefore, only the result of theadd needs to be shifted so as to match the alignment of the store.

Dominant-Shift Policy This policy further reduces the number of streamshifts by shifting register streams to the most dominant stream offsetin an expression tree.

2. Efficient Runtime Alignment Handling

In this section, an intuitive explanation of the approach applied in apreferred embodiment of the present invention is provided in Section2.1. Then, the overall simdization framework in described in Section2.2. Section 2.3 describes an algorithm to transform an arbitrary streamshift to a shift left, and the correctness of this algorithm is provedin Section 2.4.

Note that all examples in this section have compile-time alignments, forsimplicity. It will be demonstrated, however, that the code generationalgorithm employed in a preferred embodiment of the present inventionnever uses specific properties of their values. Thus, this algorithm issuitable for runtime alignment as well.

2.1. An Intuitive Example

Consider the initial example of a[i+2]=b[i+1]+c[i+3]. Given the datalayout in FIG. 2A, memory streams a[i+2] (data stream 204), b[i+1] (datastream 200), and c[i+3] (data stream 202) have three distinctalignments, 8, 4, and, 12, respectively. Using the eager-shift policy, aminimum cost simdization of the loop involves two shifts, i.e., a shiftstream of vload b[i+1] from its original offset of 4 to 8, as depictedin FIG. 3A, and a shift stream of vload c[i+3] from offset 12 to 8, asshown in FIG. 3B.

While this approach works well for stream offsets known at compile time,it does not work for runtime alignment for the following reason.Generally, shifting a stream from offset x to offset y corresponds to aright shift when x≦y and a left shift when x≧y. When generating codesfor a right shift (as in FIG. 3A), one must combine values from thecurrent register (e.g., vload b[1] operation 300) with values from theprevious register (e.g., vload b[−3] operation 302). Contrasting this tothe algorithm for a left shift (as in FIG. 3B), one must combine thevalues from the current register (e.g., vload c[3] operation 304) withvalues from the next register (e.g., vload c[7] operation 306). Thus,when a stream offset is known only at runtime, the compiler cannotdetermine whether to generate codes that shift a stream left or right.

A key insight is to realize that this issue occurs because one isfocusing on the first value of a stream. Consider, then, the case inwhich one focuses instead on a value before the first element,specifically on the value that is at offset zero of the registercontaining the first element after the shifting. For example, in FIG.3A, the first value of the stream is b[1] (value 307), so b[−1] (value308) is the value that will be at offset zero after shifting the streamto offset 8. Similarly in FIG. 3B, the first value of the stream is c[3](value 312), so c[1] (value 314) will land at offset zero in the shiftedregister stream. It should be noted that the new values can bemechanically derived from the original first values. They are simply thevalues that are 8 bytes (i.e., precisely the destination offset of thestream shift) before the original first values.

Suppose one focuses, now, on two new streams that are constructed byprepending a few values to the original b[i+1] and c[i+3] streams sothat the new streams start at, respectively, b[−1] (value 316) and c[1](value 318). These new streams are shown in FIGS. 3C and 3D with theprepended values in light grey. Using the same definition of the streamoffset as before, the offsets of the new streams are 12 and 4 bytes,respectively.

By definition, the newly prepended streams will be shifted to offsetzero. The shifted new streams yield the same sequence of registers asthat produced by shifting the original stream (highlighted with darkgrey box with light grey circle), as confirmed by visual inspection ofthe outcome of FIGS. 3A and 3C as well as FIGS. 3B and 3D. This holdsbecause the initial values of the new streams were selected precisely asthe ones that will land at offset zero in the shifted version of theoriginal streams. Since shifting any stream to offset zero is a leftshift, this prepending and shifting operation effectively transforms anarbitrary stream shift into a shift left, as shown in FIGS. 3C and 3D.

2.2. Overview of the Simdization Framework

Now an overview of the overall simdization framework that the streamshift algorithm is based upon is provided. The framework that containsthree phases:

Data reorganization phase. This phase takes, as input, an expressiontree and generate a tree with generic SIMD operations as well as streamshifts that are inserted to satisfy the alignment constraints of thesimdized operations. The augmented expression tree is called a datareorganization graph, such as the ones shown in FIGS. 2B and 2C.Different shift placement policies can be applied to minimize the numberof shifts generated.

Shift normalization phase. This phase transforms all stream shifts in adata reorganization graph to stream left shifts. The output is still adata reorganization graph.

Code generation phase. This phase takes a data reorganization graph asinput and maps generic SIMD operations and left shift operations tomachine instructions. Specifically, the algorithm maps vshiftleft tonative permutation instructions that “shifts” across a pair of vectorregisters, e.g., vec_perm on VMX. This phase also addresses issues suchas resulting loads when shifting a stream, handling unknown loop countsand multiple statements, and efficient prologue/epilogue generation.

Of primary importance to a preferred embodiment of the present inventionis the shift normalization phase that converts arbitrary stream shiftsto stream shift left. The other two phases function essentially asdescribed in the incorporated EICHENBERGER reference. Therefore, therest of the section will focus on the shift normalization algorithm.

2.3. Transforming a Stream Shift to Shift Left

As illustrated in Section 2.1, an arbitrary stream shift,vshiftstream(S,x), can be converted to a stream shift left by shifting aderived stream, one that starts exactly x bytes before the first valueof S, to offset zero. For the ease of description, introduce twooperators are introduced: Prepend(S,x), which prepends x bytes at thebeginning of stream S, and Skip(S, x), which skips the first x bytes ofstream S. Using these two new operators, the above statement can berestated as,vshiftstream(S,y)

Skip(vshiftstream(Prepend(S,y),0),y).   (1)

Consider now the Skip operation in Equation (1). In this equation, onealways skips y<V bytes from a register stream with offset zero. (Bydefinition, vshiftstream(Prepend(S,y),0) has an offset of zero.) Since aregister stream is a sequence of V byte wide registers, skippingstrictly less than V bytes from offset 0 never skips a whole registerand thus has no effect on which registers to produce in a registerstream. It only serves for bookkeeping purposes to maintain that thetransformed stream has the same offset and length properties as theoriginal stream. Thus, it can be safely ignored during the codegeneration phase.

For the Prepend operation in Equation (1), there are two cases toconsider. When prepending to a memory stream, one simply subtracts xbytes from the memory address. Directly prepending to a register streamis not feasible. However, one can propagate Prepend operations to theleaves of an expression tree until memory streams are reached. Below wedescribe how to perform Prepend for each type of nodes in a datareorganization graph.

VLOAD(addr(i)) This node represents a vector load from a stride-oneaccesses addr(i). Therefore,Prepend(VLOAD(addr(i)),x)

VLOAD(addr(i)−x)   (2)

VOP(src₁, . . . , src_(n)) This node represents a generic operation thattakes as input register streams associated with nodes src₁, . . . ,src_(n) and produces one output register stream. (Generic operationsrepresent all vectorizable operations except for the ones that shufflevalues inside vector registers or the ones that convert data ofdifferent data sizes.) Thus,Prepend(VOP(src₁, . . . , src_(n)),x)

VOP(Prepend(src₁,x), . . . , Prepend(src_(n),x))   (3)

VSHIFTSTREAM(src,to) This node shifts the register stream associatedwith the input node src to offset to, producing a register stream with astream offset to. Thus,Prepend(VSHIFTSTREAM(src,to),x)

VSHIFTSTREAM(Prepend(src,x),(to−x)modV)   (4)

In FIG. 4, pseudocode for a shift normalization routine is depicted,where the function Normalizestream recursively traverses the tree fromthe root of a data reorganization graph until all vshiftstream arenormalized. Through an application of the routine depicted in FIG. 4, adata reorganization graph of the type described in EICHENBERGER may betransformed into a normalized graph in which all stream shifts have beenreplaced with left shifts. In this way, code may be generated in whichthe actual degree of misalignment between the data streams is not knownuntil runtime.

2.4. Proof of Correctness

In this section, the correctness of two important equations in Section2.3 is proved. The first theorem demonstrates the validity of sinking aprepend past a stream shift, i.e., Equation (4).

Theorem 1. The following equality holds for an arbitrary stream S andV-byte wide SIMD unit:Prepend(VSHIFTSTREAM(S,to),x)≡VSHIFTSTREAM((S,x),(to−x)modV)Proof. As a preliminary step, the properties of Prepend(S,x) are firstdefined as functions of those of S. As x bytes are added at the head ofthe stream, the offset and length of the prepended stream becomes(Offset(S)−x)modV and Length(S)+x, respectively. Similarly, the offsetand length properties of VSHIFTSTREAM(S,to) becomes to and Length(S),respectively.

The equality of the two streams is now proven by demonstrating that theyderive from the same register stream and have the same offset and lengthproperties. Offset(Prepend(VSHIFTSTREAM(S, = (Offset(VSHIFTSTREAM(S,to), x)) to)) − x) mod V = (to − x) mod V Length(Prepend(VSHIFTSTREAM(S,= Length(VSHIFTSTREAM(S, to), x)) to)) + x = Length(S) + xOffset(VSHIFTSTREAM(Prepend(S, = (to − x) mod V x), (to − x) mod V))Length(VSHIFTSTREAM(prepend(S, = Length(S) + x x), (to − x) mod V)□Using Theorem 1, the validity of transforming arbitrary stream shift tostream shift left, i.e., Equation (1), can be demonstrated.

Theorem 2. A register stream S with arbitrary offset can be shifted toan arbitrary target offset to by (1) prepending to bytes to S, (2)shifting the resulting stream to offset zero, and (3) skipping the firstto values of the resulting stream.

Proof. Since Skip is a reciprocal of Prepend, the followingS₁=Skip(Prepend(S₁,x),x) holds for any stream S₁ Let S₁ beVSHIFTSTREAM(S,to), it can be stated thatVSHIFTSTREAM(S,to)≡Skip(Prepend(VSHIFTSTREAM(s,to),to),to).

Using Theorem 1 to permute Prepend and VSHIFTSTREAM, one obtains,VSHIFTSTREAM(S,to)≡Skip(VSHIFTSTREAM(Prepend(S,to),0)to).3. Alignment Handling for Length Conversion For the purpose ofdescribing a preferred embodiment of the present invention, the term“length conversion operation” is defined as any operation that convertsa stream into a stream of a different length. The most common lengthconversion operations are type conversions between data of differentsizes. When processing typecasts (as in the C programming language,which supports long and short “int” types, for example), the primaryfocus is on the data reorganization aspect of type conversion. Furtherdata processing beyond data reorganization, such as sign extensions orfloating point conversions, for example, can be handled by additionalnon-length-conversion vector operations.

Two types of length conversion operations are defined.

VPACK(S,f). This operation packs a stream S by a factor f, e.g., aconversion from 4 to 2 byte data types is a vpack with a factor of 2.The length of the packed stream is divided by f and its offset isrepresented as,Offset(VPACK(S,f))=Offset(S)/f.   (5)

VUNPACK(S,f). This operation unpacks stream S by a factor f, e.g.,conversion from 4 to 8 byte data types is a vunpack with a factor of 2.The of the unpacked stream is multiplied by f and its offset is,Offset(VUNPACK(S,f))=Offset(S)*f.   (6)

Length conversions have a significant impact on the simdizationframework. The rest of the section explains how to incorporate them intothe three phases of the framework.

3.1. Data Reorganization Phase

The scaling effect of length conversion on stream offsets affects allbut the least optimized Zero-shift alignment policy. The Zero-shiftpolicy is not affected by length conversions because the scaling impacton an offset of value 0 still results in an offset of 0. As defined inSection 1.3 and the incorporated EICHENBERGER application (in theabsence of length conversions), the Eager-shift policy shifts eachmisaligned load stream directly to the alignment of the store. In thepresence of length conversions, the store alignment is still propagatedto load nodes, but its alignment value is scaled up/down by thepacking/unpacking factors when traversing length conversion nodes.(Since stream offsets are propagated from the store to the loads, in thereverse direction of the data flow, Equations (5) and (6) are used inthe reverse direction.) Similarly in the Lazy-shift policy, the targetshift offset is also scaled when moving stream shifts past a pack/unpacknode, i.e.,VPACK(VSHIFTSTREAM(S,to),f)≡VSHIFTSTREAM(VPACK(S,f),to/f)VUNPACK(VSHIFTSTREAM(S,to),f)≡VSHIFTSTREAM(VUNPACK(S,f),to*f)3.2 Stream Shift Normalization Phase

In the normalization phase, the implementation of Prepend is augmentedto accommodate length conversions. Consider the example ofa[i+5]=(short)b[i+3] where a is an array of short and b is an array ofinteger. FIG. 5 illustrates the streams of a valid simdization of theloop. Using the Prepend algorithm described in Section 2.3, the originalb[i+3] memory stream (dark grey) starting at b[3] (value 500) isprepended by 20 bytes so as to start at b[−2] (value 502) (prependedvalues being displayed in light grey). When loading b[−2] (loadoperation 508) from memory, the SIMD load unit truncates the address at16 byte boundaries and loads b[−4] . . . b[−1] (values 506). However, asshown in FIG. 5, because of packing node (vpack operation 510) betweenthe load and the stream shift, the b[−8] . . . b[−1] values (values 507)are what are needed. (For clarity, this discussion focuses on thegeneration of the first batch of values in FIG. 5 as an illustration ofwhat happens in the steady state. When processing the first (or last)batch of values, it is sometime possible to eliminate some of thecomputations (e.g., vload b[−6] operation 5550) that do not impact thefinal values that can legally be stored. However, no such eliminationcan occur in the steady state.)

The solution employed by a preferred embodiment of the present inventionis to eliminate the dependence on address truncation that occurs at thememory operations by explicitly performing the desired truncation at theinput stream of the stream shift operation. The solution is to furtherprepend the already prepended input stream of vshiftstream to the valuethat is at offset zero in the input register. For example, since theprepended input stream is b[−2] (values 502, 514), the stream is furtherprepended so that b[−8] (values 503, 516) is now the initial streamvalue. As can be visually seen from the figure by tracing the b[−8]value (value 516), the memory load truncation that used to occur at theload operation now occurs at the vicinity of shift stream operation 518,and is of the correct amount. The result may then be directly stored inthe proper memory location for array “a” (store operation 520), with theresult being truncated such that value 521 becomes the first valuestored in array “a” (at value 522).

Theorem 3. In the presence of length conversion, a stream S can beshifted to an arbitrary target offset to by (1) prepending stream S byto+(Offset(S)−to)modV bytes, (2) skipping the first (Offset(S)−to)modVvalues of the resulting stream, (3) shifting the resulting stream tooffset zero, and (4) skip to bytes of the shifted stream.

Note that, in Theorem 3, steps (1) and (3) produce streams of offsetzero and in steps (2) and (4) the skip bytes are less than V. Therefore,the skips are only for bookkeeping purposes and can be safely ignored bycode generation. Theorem 3 may be proved mathematically in a similarfashion to Theorem 2.

3.3. Code Generation Phase

During the code generation, vpack and vunpack are mapped to nativepermutation instructions. Some multimedia platforms even provide nativepacking and unpacking instructions to perform these operations, e.g.,VMX. For machines where length conversions and stream shifts are bothmapped to some sort of permutation instruction, the total number ofextra permutation operations can be further reduced by merging togetherpairs of consecutive length conversion and stream shift.

4. Method Overview and Example Hardware Platform Description

FIG. 6 is a flowchart representation of a process of simdizing a loop inaccordance with a preferred embodiment of the present invention. First,a naive vectorized representation of the loop is obtained without regardfor the alignment or misalignment of the various memory streams involved(block 600). Next, a data reorganization graph is generated from thenaive vectorization (block 602). Then, stream shift operations areapplied to the data reorganization graph to satisfy the data-alignmentconstraints of the loop (block 604). The arbitrary-direction shiftoperation are then converted into left shifts, taking into account notonly the shift operations, but also any pack or unpack operations neededto handle data-type conversion (block 606). (Note: this conversion toleft shifts may be omitted if the alignment constraints are completelyknown at compile time or if the above-described “zero-shift” policy isused.) Finally, code is generated from the transformed datareorganization graph, including code for shift, pack, and unpackoperations (block 608).

FIG. 7 illustrates information handling system 701 which is a simplifiedexample of a computer system capable of performing the computingoperations described herein. Computer system 701 includes processor 700which is coupled to host bus 702. A level two (L2) cache memory 704 isalso coupled to host bus 702. Host-to-PCI bridge 706 is coupled to mainmemory 708, includes cache memory and main memory control functions, andprovides bus control to handle transfers among PCI bus 710, processor700, L2 cache 704, main memory 708, and host bus 702. Main memory 708 iscoupled to Host-to-PCI bridge 706 as well as host bus 702. Devices usedsolely by host processor(s) 700, such as LAN card 730, are coupled toPCI bus 710. Service Processor Interface and ISA Access Pass-through 712provides an interface between PCI bus 710 and PCI bus 714. In thismanner, PCI bus 714 is insulated from PCI bus 710. Devices, such asflash memory 718, are coupled to PCI bus 714. In one implementation,flash memory 718 includes BIOS code that incorporates the necessaryprocessor executable code for a variety of low-level system functionsand system boot functions.

PCI bus 714 provides an interface for a variety of devices that areshared by host processor(s) 700 and Service Processor 716 including, forexample, flash memory 718. PCI-to-ISA bridge 735 provides bus control tohandle transfers between PCI bus 714 and ISA bus 740, universal serialbus (USB) functionality 745, power management functionality 755, and caninclude other functional elements not shown, such as a real-time clock(RTC), DMA control, interrupt support, and system management bussupport. Nonvolatile RAM 720 is attached to ISA Bus 740. ServiceProcessor 716 includes JTAG and I2C buses 722 for communication withprocessor(s) 700 during initialization steps. JTAG/I2C buses 722 arealso coupled to L2 cache 704, Host-to-PCI bridge 706, and main memory708 providing a communications path between the processor, the ServiceProcessor, the L2 cache, the Host-to-PCI bridge, and the main memory.Service Processor 716 also has access to system power resources forpowering down information handling device 701.

Peripheral devices and input/output (I/O) devices can be attached tovarious interfaces (e.g., parallel interface 762, serial interface 764,keyboard interface 768, and mouse interface 770 coupled to ISA bus 740.Alternatively, many I/O devices can be accommodated by a super I/Ocontroller (not shown) attached to ISA bus 740.

In order to attach computer system 701 to another computer system tocopy files over a network, LAN card 730 is coupled to PCI bus 710.Similarly, to connect computer system 701 to an ISP to connect to theInternet using a telephone line connection, modem 775 is connected toserial port 764 and PCI-to-ISA Bridge 735.

While the computer system described in FIG. 7 is capable of executingthe processes described herein, this computer system is simply oneexample of a computer system. Those skilled in the art will appreciatethat many other computer system designs are capable of performing theprocesses described herein.

One of the preferred implementations of the invention is a clientapplication, namely, a set of instructions (program code) or otherfunctional descriptive material in a code module that may, for example,be resident in the random access memory of the computer. Until requiredby the computer, the set of instructions may be stored in anothercomputer memory, for example, in a hard disk drive, or in a removablememory such as an optical disk (for eventual use in a CD ROM) or floppydisk (for eventual use in a floppy disk drive), or downloaded via theInternet or other computer network. Thus, the present invention may beimplemented as a computer program product for use in a computer. Inaddition, although the various methods described are convenientlyimplemented in a general purpose computer selectively activated orreconfigured by software, one of ordinary skill in the art would alsorecognize that such methods may be carried out in hardware, in firmware,or in more specialized apparatus constructed to perform the requiredmethod steps. Functional descriptive material is information thatimparts functionality to a machine. Functional descriptive materialincludes, but is not limited to, computer programs, instructions, rules,facts, definitions of computable functions, objects, and datastructures.

While particular embodiments of the present invention have been shownand described, it will be obvious to those skilled in the art that,based upon the teachings herein, that changes and modifications may bemade without departing from this invention and its broader aspects.Therefore, the appended claims are to encompass within their scope allsuch changes and modifications as are within the true spirit and scopeof this invention. Furthermore, it is to be understood that theinvention is solely defined by the appended claims. It will beunderstood by those with skill in the art that if a specific number ofan introduced claim element is intended, such intent will be explicitlyrecited in the claim, and in the absence of such recitation no suchlimitation is present. For non-limiting example, as an aid tounderstanding, the following appended claims contain usage of theintroductory phrases “at least one” and “one or more” to introduce claimelements. However, the use of such phrases should not be construed toimply that the introduction of a claim element by the indefinitearticles “a” or “an” limits any particular claim containing suchintroduced claim element to inventions containing only one such element,even when the same claim includes the introductory phrases “one or more”or “at least one” and indefinite articles such as “a” or “an”; the sameholds true for the use in the claims of definite articles.

1. A computer-implemented method comprising: identifying a loopiterating over a plurality of continuous streams of memory in astride-one fashion; generating a data reorganization graph from theloop, wherein the data reorganization graph includes one or more streamshift operations that adjust alignment of one or more of the pluralityof continuous streams of memory; and transforming at least one streamshift operation from the one or more stream shift operations to allowthe at least one stream shift operation to shift a data stream by anamount that is unknown at compile time.
 2. The method of claim 1,wherein the transforming further comprises: transforming the at leastone stream shift operation such that the at least one stream shiftoperation shifts the data stream to the left.
 3. The method of claim 2,wherein the transforming further comprises: causing one or more valuesto be prepended to the data stream prior to shifting the data stream. 4.The method of claim 3, wherein the transforming further comprises:performing an operation on the data stream to obtain a result; andcausing a corresponding one or more values from the result to betruncated from the result, wherein the corresponding one or more valuescorrespond to the one or more values prepended to the data stream priorto shifting the data stream.
 5. The method of claim 3, wherein the datastream is shifted such that a first value of the one or more prependedvalues is shifted to a zero offset.
 6. The method of claim 1, furthercomprising: interposing a data length conversion operation into the datareorganization graph, wherein the data length conversion operationrepresents a conversion from a data type having a first length to a datatype having a second length.
 7. The method of claim 1, furthercomprising: applying a simdization policy to the data reorganizationgraph, wherein the simdization policy is one of a zero shift policy, aneager shift policy, a lazy shift policy, and a dominant shift policy. 8.A computer program product in a computer-readable medium comprising:means for identifying a loop iterating over a plurality of continuousstreams of memory in a stride-one fashion; means for generating a datareorganization graph from the loop, wherein the data reorganizationgraph includes one or more stream shift operations that adjust alignmentof one or more of the plurality of continuous streams of memory; andtransforming means for transforming at least one stream shiftoperation-from the one or more stream shift operations to allow the atleast one stream shift operation to shift a data stream by an amountthat is unknown at compile time.
 9. The computer program product ofclaim 8, wherein the transforming means further comprises: means fortransforming the at least one stream shift operation such that the atleast one stream shift operation shifts the data stream to the left. 10.The computer program product of claim 9, wherein the transforming meansfurther comprises: means for causing one or more values to be prependedto the data stream prior to shifting the data stream.
 11. The computerprogram product of claim 10, wherein the transforming means furthercomprises: means for performing an operation on the data stream toobtain a result; and causing a corresponding one or more values from theresult to be truncated from the result, wherein the corresponding one ormore values correspond to the one or more values prepended to the datastream prior to shifting the data stream.
 12. The computer programproduct of claim 10, wherein the data stream is shifted such that afirst value of the one or more prepended values is shifted to a zerooffset.
 13. The computer program product of claim 8, further comprising:means for interposing a data length conversion operation into the datareorganization graph, wherein the data length conversion operationrepresents a conversion from a data type having a first length to a datatype having a second length.
 14. The computer program product of claim8, further comprising: means for applying a simdization policy to thedata reorganization graph, wherein the simdization policy is one of azero shift policy, an eager shift policy, a lazy shift policy, and adominant shift policy.
 15. An information-handling system comprising: atleast one processor; one or more data storage units accessible by the atleast one processor; and functional descriptive material containedwithin the data storage units that, when executed by the at least oneprocessor, directs the at least one processor to perform actions of:identifying a loop iterating over a plurality of continuous streams ofmemory in a stride-one fashion; generating a data reorganization graphfrom the loop, wherein the data reorganization graph includes one ormore stream shift operations that adjust alignment of one or more of theplurality of continuous streams of memory; and transforming at least onestream shift operation from the one or more stream shift operations toallow the at least one stream shift operation to shift a data stream byan amount that is unknown at compile time.
 16. The information-handlingsystem of claim 15, wherein the transforming further comprises:transforming the at least one stream shift operation such that the atleast one stream shift operation shifts the data stream to the left. 17.The information-handling system of claim 16, wherein the transformingfurther comprises: causing one or more values to be prepended to thedata stream prior to shifting the data stream.
 18. Theinformation-handling system of claim 17, wherein the transformingfurther comprises: performing an operation on the data stream to obtaina result; and causing a corresponding one or more values from the resultto be truncated from the result, wherein the corresponding one or morevalues correspond to the one or more values prepended to the data streamprior to shifting the data stream.
 19. The information-handling systemof claim 17, wherein the data stream is shifted such that a first valueof the one or more prepended values is shifted to a zero offset.
 20. Theinformation-handling system of claim 15, further comprising: applying asimdization policy to the data reorganization graph, wherein thesimdization policy is one of a zero shift policy, an eager shift policy,a lazy shift policy, and a dominant shift policy.